#include "stdafx.h"
#include "CppUnitTest.h"
#include "DicomFileReader.h"

#include <string>
#include <vector>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;

namespace UnitTests
{
   TEST_CLASS(DicomFileReaderTests)
   {
   private:
      DicomFileReader* sut;

   public:
      TEST_METHOD_INITIALIZE(TestInitialize)
      {
         sut = new DicomFileReader("../TestData/test-MR.dcm");
      }

      TEST_METHOD_CLEANUP(TestCleanup)
      {
         delete sut;
      }

      TEST_METHOD(GetAttributeValueReadsSingleValueOfSingleVm)
      {
         // given
         wstring attribute(L"0018,1020");
         wstring defaultValue(L"_default_");

         // when
         wstring actual = sut->GetAttributeValue(attribute, defaultValue);

         // then
         Assert::AreEqual(L"4VA15A", actual.c_str());
      }

      TEST_METHOD(GetAttributeValueReadsAllValuesOfMultiVm)
      {
         // given
         wstring attribute(L"0008,0008");
         wstring defaultValue(L"_default_");

         // when
         wstring actual = sut->GetAttributeValue(attribute, defaultValue);

         // then
         Assert::AreEqual(L"ORIGINAL\\PRIMARY\\M\\HEADER_CORRECTED", actual.c_str());
      }

      TEST_METHOD(GetAttributeValueReturnsDefaultValueForNonExistingAttribute)
      {
         // given
         wstring attribute(L"0008,0051");
         wstring defaultValue(L"_default_");

         // when
         wstring actual = sut->GetAttributeValue(attribute, defaultValue);

         // then
         Assert::AreEqual(L"_default_", actual.c_str());
      }

      TEST_METHOD(GetAttributeValueReturnsEmptyValue)
      {
         // given
         delete sut;
         sut = new DicomFileReader("../TestData/test-EPDF.dcm");
         wstring attribute(L"0008,0090");
         wstring defaultValue(L"_default_");

         // when
         wstring actual = sut->GetAttributeValue(attribute, defaultValue);

         // then
         Assert::AreEqual(L"", actual.c_str());
      }

      TEST_METHOD(GetAttributeValueReturnsValidResultForNestedAttribute)
      {
         // given
         delete sut;
         sut = new DicomFileReader("../TestData/test-EPDF.dcm");
         wstring attribute(L"0008,1140[1].0040,a170[0].0008,0100");
         wstring defaultValue(L"_default_");

         // when
         wstring actual = sut->GetAttributeValue(attribute, defaultValue);

         // then
         Assert::AreEqual(L"SCLERAL_IMG_L", actual.c_str());
      }
   };
}